// ~ CopyRight © 2012 USTC SINOVATE  SOFTWARE CO.LTD All Rights Reserved.
package com.cmcc.zysoft.infocollection.controller;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.cmcc.zysoft.framework.utils.StringUtil;
import com.cmcc.zysoft.infocollection.common.BaseController;
import com.cmcc.zysoft.infocollection.service.ResourcePcService;
import com.cmcc.zysoft.spring.security.util.Constant;
import com.cmcc.zysoft.sysmanage.service.CompanyService;

/**
 * @author 李三来
 * <br />邮箱： li.sanlai@ustcinfo.com
 * <br />描述：登录控制器
 * <br />版本:1.0.0
 * <br />日期： 2013-1-13 上午10:29:08
 * <br />CopyRight © 2012 USTC SINOVATE  SOFTWARE CO.LTD All Rights Reserved.
 */
@Controller
@RequestMapping("/")
public class LoginController extends BaseController {
	
	/**
	 * 登录页面.
	 */
	private static final String LOGIN_VIEW = "login";
	
	/**
	 * 报表展示.
	 */
	private static final String ECHART_VIEW = "echarts/infoAnalyze";
	
	/**
	 * 属性名称: companyService.
	 * 类       型: CompanyService.
	 */
	@Resource
	private CompanyService companyService;
	
	/**
	 * 属性名称: resourcePcService.
	 * 类       型: ResourcePcService.
	 */
	@Resource
	private ResourcePcService resourcePcService;
	
	/**
	 * 日志.
	 */
	private static Logger _logger = LoggerFactory.getLogger(LoginController.class);	
	
	/**
	 * 跳转到登录页面.
	 * @param request 请求
	 * @param errorCode 错误码
	 * @return String
	 */
	@RequestMapping("/login.htm")
	public String loginViewFirst(HttpServletRequest request, String errorCode) {
		if(!StringUtil.isNullOrEmpty(errorCode) && !StringUtil.isNullOrEmpty(Constant.ERROR_MESSAGE_MAP.get(errorCode))) {
			request.setAttribute(Constant.ERROR_MESSAGE, Constant.ERROR_MESSAGE_MAP.get(errorCode));
		}
		return LOGIN_VIEW;
	}
	
	/**
	 * 跳转到登录页面.
	 * @param request 请求
	 * @param errorCode 错误码
	 * @return String
	 */
	@RequestMapping("/")
	public String loginViewSecond(HttpServletRequest request, String errorCode) {
		if(!StringUtil.isNullOrEmpty(errorCode) && !StringUtil.isNullOrEmpty(Constant.ERROR_MESSAGE_MAP.get(errorCode))) {
			request.setAttribute(Constant.ERROR_MESSAGE, Constant.ERROR_MESSAGE_MAP.get(errorCode));
		}
		return LOGIN_VIEW;
	}
	
	/**
	 * 跳转到登录页面.
	 * @param request 请求
	 * @param errorCode 错误码
	 * @return String
	 */
	@RequestMapping("/login")
	public String loginViewThird(HttpServletRequest request, String errorCode) {
		if(!StringUtil.isNullOrEmpty(errorCode) && !StringUtil.isNullOrEmpty(Constant.ERROR_MESSAGE_MAP.get(errorCode))) {
			request.setAttribute(Constant.ERROR_MESSAGE, Constant.ERROR_MESSAGE_MAP.get(errorCode));
		}
		return LOGIN_VIEW;
	}
	
	/**
	 * 跳转到各月份采集数据柱状图报表.
	 * @param modelMap modelMap
	 * @return String
	 */
	@RequestMapping("/echarts/infoAnalyze.htm")
	public String infoAnalyze(ModelMap modelMap) {	
		_logger.debug("#跳转到信息柱状图报表");
		String Mon1 = "month1";
		String Mon2 = "month2";
		String Mon3 = "month3";
		String Mon4 = "month4";
		String Mon5 = "month5";
		String Mon6 = "month6";
		String Mon7 = "month7";
		String Mon8 = "month8";
		String Mon9 = "month9";
		String Mon10 = "month10";
		String Mon11 = "month11";
		String Mon12 = "month12";
		List<Map<String, Object>> list = this.resourcePcService.getResourceCount();
		System.out.print("信息采集次数统计："+list+"\n");		
		String json = "{tooltip : {trigger: 'axis'},legend: {data:['新增信息','更新信息']},";
		json +="toolbox: {show : true,"+
				"feature : {mark : true,dataView : {readOnly: false},"+
					"magicType:['line', 'bar'],"+
					"restore : true,"+
					"saveAsImage : false}},";
		json +=	"calculable : true,";
		json += "xAxis : [{type : 'category',data:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']}],";
		json += "yAxis:[{type:'value',splitArea : {show : true}}],";
		json += "series:[{name:'新增信息',type:'bar',data:[";
		json += list.get(0).get(Mon1)+","+list.get(0).get(Mon2)+","+list.get(0).get(Mon3)+","+
				list.get(0).get(Mon4)+","+list.get(0).get(Mon5)+","+list.get(0).get(Mon6)+","+
				list.get(0).get(Mon7)+","+list.get(0).get(Mon8)+","+list.get(0).get(Mon9)+","+
				list.get(0).get(Mon10)+","+list.get(0).get(Mon11)+","+list.get(0).get(Mon12)+"]},";
		json += "{name:'更新信息',type:'bar',data:[";
		json += list.get(1).get(Mon1)+","+list.get(1).get(Mon2)+","+list.get(1).get(Mon3)+","+
				list.get(1).get(Mon4)+","+list.get(1).get(Mon5)+","+list.get(1).get(Mon6)+","+
				list.get(1).get(Mon7)+","+list.get(1).get(Mon8)+","+list.get(1).get(Mon9)+","+
				list.get(1).get(Mon10)+","+list.get(1).get(Mon11)+","+list.get(1).get(Mon12)+"]}]}";		
		modelMap.put("data", json);
		return ECHART_VIEW;
	}
	
	/**
	 * 跳转到各地市汇总地图报表.
	 * @param modelMap modelMap
	 * @return String
	 */
	@RequestMapping("/echarts/infoSumAnalyze.htm")
	public String infoSumAnalyze(ModelMap modelMap) {	
		_logger.debug("#跳转到各地市汇总地图报表");
		String[] arr = {"六安市","安庆市","滁州市","宣城市","阜阳市","宿州市","黄山市","巢湖市","亳州市","池州市",
				"合肥市","蚌埠市","芜湖市","淮北市","淮南市","马鞍山市","铜陵市"};	
		List<Map<String,Object>> list = this.resourcePcService.getResourceSumCount();
		System.out.print("各地市汇总数据："+list+"\n");
		String json = "{tooltip : {trigger: 'item'},legend: {orient: 'vertical',x:'right',data:['汇总数据']},"+
			"dataRange: {min: 0,max: 50,color:['orange','yellow'],text:['高','低'],calculable : true},"+
			"series : [{name: '汇总数据',type: 'map',mapType: '安徽',selectedMode : 'single',"+
			"itemStyle:{normal:{label:{show:true}},emphasis:{label:{show:true}}},"+
			"data:[";
		for(int i=0;i<arr.length;i++){
			json += "{name: '"+arr[i]+"',value: "+list.get(0).get(arr[i])+"}";
			if (i<arr.length-1) {
				json += ",";
			}	
		}
		json += "]}]}";	
		modelMap.put("data", json);
		return ECHART_VIEW;
	}
}